<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>学校通知-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="weui_cells_title">发送通知</div>
			<div class="weui_cells weui_cells_form">
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <textarea id="content" class="weui_textarea" placeholder="请输入通知内容……" rows="5"></textarea>
	                </div>
	            </div>
	            <div class="weui_uploader">
                       
                       <div class="weui_uploader_bd">
                            <ul class="weui_uploader_files img-click" id="img1">
	                        </ul>
	                        <div class="weui_uploader_input_wrp" id="filePicker" style="margin-bottom: 20px; margin-left: 15px; width: 60px; height: 60px; border-radius: 5px;">
	                           
	                        </div>
                       </div>
                   </div>
	        </div>
	        <div class="weui_cells weui_cells_access">

	            <a class="weui_cell" id="sd1">
	                <div class="weui_cell_hd"><img src="<%=basePath %>/images/fasongduixiang@3x.png" alt="" style="width:20px;margin-right:10px;display:block"></div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>发送对象</p>
	                </div>
	                <div class="weui_cell_ft">请选择</div>
	            </a>
	        </div>
	        
	        <div class="weui_cells weui_cells_access">
	        	<form id="uploadForm" enctype="multipart/form-data" method="post">
		        	<a class="weui_cell" href="javascript:;">
		                <div class="weui_cell_hd"><img src="<%=basePath %>/images/wenjianchuanyue@3x.png" alt="" style="width:20px; margin-right:10px;display:block"></div>
		                <div class="weui_cell_bd weui_cell_primary">
		                    <p>文件上传</p>
		                </div>
		                <div class="weui_btn weui_btn_mini weui_btn_primary f-white bg-blue">
							上传<input class="weui_uploader_input" type="file" id="uploadTheFile">
						</div>
		            </a>
		         </form>
	        </div>
	        <div class="upload_info hide" id="fileDiv">
                <ul id="fileList"></ul>
                <div class="cover hide"></div>
                <img class="hide" src="<%=basePath %>/images/loading.gif" alt="">
            </div>
	        <div class="weui_btn_area">
		        <a href="javascript:" class="weui_btn bg-blue" id="notice-submit">确认发送</a>
		    </div>
		    <!-- 今日通知 start -->
		    <div class="weui_cells">
			    <div class="weui_cell lblue tz-history-title" style="background-color: #fff;">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p class="bold pr">今日已发通知 <a href="<%=basePath %>/ls/notices/sender/list?nt=${noticeType}" class="f-blue">历史记录</a></p>
	                </div>
	            </div>
		        <div class="ly-lsjl">
					<div class="weui_panel weui_panel_access">
			            <div class="weui_panel_bd" id="noticeList">
			                
			            </div>
			        </div>
				</div> 
			</div>
			
			<!-- 今日通知 end -->
			<script id="notice-table-template" type="text/x-handlebars-template">
				{{#each rows}}
				<a href="<%=basePath %>/ls/notices/detail/{{id}}" style="display: block;color: #000;">
					<div class="weui_cell moments__post" style="padding: 10px 5px;">
			          <div class="weui_media_bd" style="padding-left:0">
			            <p class="weui_media_desc" style="color:#999;">{{dateFormat createTime}}</p>
			            <!-- post内容 -->
			            <p class="paragraph" style="padding-top: 10px;">{{content}}</p>
			            <!-- 伸张链接 -->
			            <a class="paragraphExtender">全文</a>
			            <!-- 相册 -->
						<div class="thumbnails1">
							{{#each attachList}}
							   {{#equal attachmentType "image"}}
					           <div class="thumbnail1 img-click">
									<img onclick="imgClick(this)" class="img-max" src="${config.imgUrl}{{attachmentUrl}}">
							   </div>
							   {{/equal}}
							{{/each}}
					    </div>
						<div class="pb10">
							{{#each attachList}}
								{{#equal attachmentType "image"}}
								{{else}}
								<div class="xtbg-upload-list mb10">
									<div class="xtbg-upload-list-inner">
										<p>{{attachmentName}}</p>
										<a href="${config.imgUrl}{{attachmentUrl}}" class="weui_btn weui_btn_mini weui_btn_primary f-white bg-blue">查看</a>
									</div> 
								</div>
								{{/equal}}
							{{/each}}
						</div>
			          </div>
					</div>
				</a>
			{{/each}}
		</script>  
		    <div class="maskAll"></div>
	</div>
	</div>
	
	<!--弹窗-->				
	<div class="weui_mask ueureiu weui_mask_visible" style="display: none;z-index: 600">
	</div>
	<div id="ls_xs_check" class="weui_dialog weui_dialog_visible" style="display: none;z-index: 700;">
		<div class="weui_dialog_bd" style="padding: 0;">
			<div class="weui_panel weui_panel_access">
	            <div class="weui_panel_bd">
	                <a href="javascript:" id="ls_div" class="weui_media_box weui_media_appmsg">
	                    <div class="weui_media_bd tleft">
	                        <h4 class="weui_media_title">${config.appName}组织架构</h4>
	                        <p class="weui_media_desc">学校所有教师可见</p>
	                    </div>
	                </a>
	                <a href="javascript:" id="xs_div" class="weui_media_box weui_media_appmsg">
	                    <div class="weui_media_bd tleft">
	                        <h4 class="weui_media_title">${config.appName}学生家长</h4>
	                        <p class="weui_media_desc">学校所有家长可见</p>
	                    </div>
	                </a>
	            </div>
	        </div>
		</div>
	</div>
	<!--End弹窗-->
	
	<!-- 老师组织架构 start-->
	<div id="ls_div_box" class="weui_tab tab-bottom" style="display:none;z-index: 600;background-color: #f8f8f8;">
			<div class="weui_tab_bd">
		        <div class="weui-header bg-blue"> 
		        	<div class="weui-header-left" id="teacherBack"> <a class="icon icon-109 f-white">取消</a>  </div>
					<h1 class="weui-header-title">培立实验小学组织架构</h1>
				</div>
		        
		        <!--下拉选择-->
		        <div class="page-bd">  
			         <ul id="teacherList">
			     	 </ul>
			    </div>
			
	    <script id="teacher-table-template" type="text/x-handlebars-template">	
 				{{#each list}}
					<li class="list1">
		                <div class="weui-flex">
		                	<span class="list_c1 mui-radio">
							<label class="weui_cells_checkbox weui_check_label" for="{{groupId}}">
								<div class="weui_cell_hd">
									<input type="checkbox" class="weui_check" id="{{groupId}}">
					        		<i class="weui_icon_checked"></i>
								</div>
							</label>
							</span>
		                   	<p class="weui-flex-item js-category"> {{groupName}}</p>
		                    <span class="js-category"><i class="icon icon-74"></i> 下级</span>
		                </div>
		                <div class="page-category js-categoryInner">
							{{#each subList}}
		                    	{{#if subList}}
								<div class="weui_cells" style="margin: 0;">
									<div class="weui_cell">
										<div class="weui_cell_hd list_c2" style="margin-right: 10px;">
											<label class="weui_cells_checkbox weui_check_label" for="{{parentGroupId}}_{{groupId}}">
												<div class="weui_cell_hd">
													<input type="checkbox" class="weui_check" id="{{parentGroupId}}_{{groupId}}">
					        						<i class="weui_icon_checked"></i>
												</div>
											</label>
										</div>
										<div class="weui_cell_bd weui_cell_primary" onclick="selectmenu('{{parentGroupId}}_{{groupId}}');">
											<p>{{groupName}}（{{teacherCount}}人）</p>
										</div>
										{{#if teacherCount}}
											<span id="cell_{{parentGroupId}}_{{groupId}}" class="icon icon-74" onclick="selectmenu('{{parentGroupId}}_{{groupId}}');"></span>
										{{/if}}
									</div>
									<div style="display: none;" id="menu_{{parentGroupId}}_{{groupId}}">
										<ul class="list_3">
											{{#each subList}}
						            			<li><div class="weui_cell_hd list_c3" style="display: inline-flex;padding-left: 10px;">
													<label class="weui_cells_checkbox weui_check_label" style="padding-right: 15px;" for="{{parentGroupId}}_{{groupId}}_{{teacherId}}">
															<input type="checkbox" class="weui_check" value="{{teacherId}}" id="{{parentGroupId}}_{{groupId}}_{{teacherId}}">
					        								<i class="weui_icon_checked"></i>
													</label>{{teacherName}}	
													</div>
												</li>
						            		{{/each}}
						            	</ul>
									</div>
								</div>
								{{else}}
									{{#if teacherId}}
									  	{{#if @first}}
											<div class="weui_cells" style="margin: 0;">									
											<ul class="list_3">
												<li><div class="weui_cell_hd list_c3" style="display: inline-flex;padding-left: 10px;">
													<label class="weui_cells_checkbox weui_check_label" style="padding-right: 15px;" for="{{groupId}}_{{teacherId}}">
														<input type="checkbox" class="weui_check" value="{{teacherId}}" id="{{groupId}}_{{teacherId}}">
					        							<i class="weui_icon_checked"></i>
													</label>{{teacherName}}
													</div>
												</li>
										{{else}}
											<li><div class="weui_cell_hd list_c3" style="display: inline-flex;padding-left: 10px;">
												<label class="weui_cells_checkbox weui_check_label" style="padding-right: 15px;" for="{{groupId}}_{{teacherId}}">
													<input type="checkbox" class="weui_check" value="{{teacherId}}" id="{{groupId}}_{{teacherId}}">
					        						<i class="weui_icon_checked"></i>
												</label>{{teacherName}}
												</div>
											</li>
										{{/if}}
										{{#if @last}}
											</ul>
										{{/if}}
									{{else}}
										{{#if teacherCount}}
										{{#compare teacherCount 0}}
										<div class="weui_cells" style="margin: 0;">									
											<ul class="list_3">
						            		<li><div class="weui_cell_hd list_c3" style="display: inline-flex;padding-left: 10px;abcd4">
												<label class="weui_cells_checkbox weui_check_label" style="padding-right: 15px;" for="{{groupId}}_{{teacherId}}">
													<input type="checkbox" class="weui_check" value="{{teacherId}}" id="{{groupId}}_{{teacherId}}">
					        						<i class="weui_icon_checked"></i>
												</label>{{teacherName}}
												</div>
											</li>
						            		</ul>
										</div>
										{{/compare}}
										{{/if}}
									{{/if}}
								{{/if}}
							{{/each}}
		                </div>
		            </li>
				{{/each}}
			</script>
	    <!--End下拉选择-->
			</div>
			<div class="weui_tabbar ">
				<div class="fsdx_tabbar">
		            <span class="left">
						<div class="weui-flex">
		                	<span style="margin-top: 13px;margin-left: 0px;">
							<label class="weui_cells_checkbox weui_check_label" for="teacherAll">
								<div class="weui_cell_hd">
									<input type="checkbox" class="weui_check" id="teacherAll">
					        		<i class="weui_icon_checked"></i>
								</div>
							</label>
							</span>
		                   	<p class="weui-flex-item"> 全选</p>
		                </div>
					</span>
		            <span class="left">人数：<label id="teacherCount">0</label></span>
		            <span class="right" id="teacherSure"><a href="javascript:">确定</a></span>
		        </div>
			</div>
		</div>
	<!-- 老师组织架构  end-->
	
	<!-- 学生组织架构 start -->
	<div id="xs_div_box" class="weui_tab tab-bottom" style="display:none; z-index:600; background-color: #f8f8f8;">
		<div class="weui_tab_bd">
	        <div class="weui-header bg-blue"> 
	        	<div class="weui-header-left" id="studentBack"> <a class="icon icon-109 f-white">取消</a>  </div>
				<h1 class="weui-header-title">${config.appName}学生家长</h1>
			</div>
	        <!--下拉选择-->
	        <div class="page-bd">  
	          <ul id="studentList">
	            
	     	  </ul>
	    	</div>
	    	<script id="student-table-template" type="text/x-handlebars-template">
				{{#each list}}
					<li class="list1">
		                <div class="weui-flex">
		                	<span class="list_c1 mui-radio">
							<label class="weui_cells_checkbox weui_check_label" for="xs_{{grade}}">
								<div class="weui_cell_hd">
									<input type="checkbox" class="weui_check" id="xs_{{grade}}">
					        		<i class="weui_icon_checked"></i>
								</div>
							</label>
							</span>
		                   	<p class="weui-flex-item js-category"> {{gradeText}}（{{studentCount}}人）</p>
		                    <span class="js-category"><i class="icon icon-74"></i> 下级</span>
		                </div>
		                <div class="page-category js-categoryInner">
							{{#each subList}}
		                    	<div class="weui_cells" style="margin: 0;">
		                    		<div class="weui_cell">
										<div class="weui_cell_hd list_c2" style="margin-right: 10px;">
											<label class="weui_cells_checkbox weui_check_label" for="{{grade}}_{{clazz}}">
												<div class="weui_cell_hd">
													<input type="checkbox" class="weui_check" value="{{grade}}_{{clazz}}" id="{{grade}}_{{clazz}}">
					        						<i class="weui_icon_checked"></i>
												</div>
											</label>
										</div>
										<div class="weui_cell_bd weui_cell_primary">
											<p>{{gradeText}}（{{clazz}}）班	（{{studentCount}}）人</p>
										</div>
									</div>
									<div style="display: none;">
										<ul class="list_3">
										</ul>
									</div>
								</div>
							{{/each}}
		                </div>
		            </li>
				{{/each}}	    	
	    	</script>
	       </div>
	   		<!--End下拉选择-->
	   		<div class="weui_tabbar">
				<div class="fsdx_tabbar">
		            <span class="left">
						<div class="weui-flex">
		                	<span style="margin-top: 13px;margin-left: 0px;">
							<label class="weui_cells_checkbox weui_check_label" for="studentAll">
								<div class="weui_cell_hd">
									<input type="checkbox" class="weui_check" id="studentAll">
					        		<i class="weui_icon_checked"></i>
								</div>
							</label>
							</span>
		                   	<p class="weui-flex-item"> 全选</p>
		                </div>
					</span>
		            <span class="left">班级数：<label id="studentCount">0</label></span>
		            <span class="right" id="studentSure"><a href="javascript:">确定</a></span>
		        </div>
			</div>
		</div>
	</div>
	<!-- 学生组织架构 end -->
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
	var teacherData = {};
	var studentData = {};
	var sendModel;
	$(function() {
		//初始化未处理附件
		initHandingAttach();
		//初始化老师组织架构
		loadTeacher();
		//初始化学生架构
		loadStudent();
		//今日通知
		loadTodayNotice();
		
		//通知提交
		$("#notice-submit").click(function() {
			noticeSubmit();
		});
		$("#studentBack").click(function() {
			$('.ueureiu').hide();
			$("#xs_div_box").hide();
			$("#studentCount").html(0);
			$("#studentAll")[0].checked = false;
			$(".weui_cell_ft").html("请选择");
			sendModel = null;
			loadStudentHtml(studentData);
		});
		//老师组织架构返回
		$("#teacherBack").click(function() {
			$('.ueureiu').hide();
			$("#ls_div_box").hide();
			$("#teacherCount").html(0);
			$("#teacherAll")[0].checked = false;
			sendModel = null;
			$(".weui_cell_ft").html("请选择");
			loadTeacherHtml(teacherData);
		});
		//弹出组织架构选择层
		$("#sd1").click(function(){
      		$(".ueureiu").show();
      		$("#ls_xs_check").show();
      	})
      	//组织架构选择层关闭
      	$(".ueureiu").click(function() {
      		$('.ueureiu').hide();
      		$("#ls_xs_check").hide();
      	})
      	//老师组织架构全选
      	$("#teacherAll").click(function() {
      		if(this.checked) {
      			var list = $("#teacherList").find("input");
      			list.each(function(i, v){
					v.checked = true;
				});
      		}else {
      			var list = $("#teacherList").find("input:checked");
      			list.each(function(i, v){
					v.checked = false;
				});
      		}
 			$("#teacherCount").html($("#teacherList").find(".list_c3 input:checked").length);
      	})
      	//学生组织架构弹出
      	$("#xs_div").click(function() {
      		sendModel = 1;
      		$('.ueureiu').show();
      		$("#ls_xs_check").hide();
      		$("#xs_div_box").show();
      		$("#studentList .js-category").each(function(i, v) {
	    		v.removeEventListener("click", categoryClick, false);
	    		v.addEventListener('click', categoryClick);
	    	})
			$('.list_c1 input').click(function() {
      			if(this.checked) {
      				var list = $(this.closest("li.list1")).find("input");
      				list.each(function(i, v){
						v.checked = true;
					});
      			}else {
      				var list_c2 = $(this.closest("li.list1")).find(".list_c2 input:checked");
      				list_c2.each(function(i, v){
						v.checked = false;
					});
      			}
      			$("#studentCount").html($("#studentList").find(".list_c2 input:checked").length);
			});
			$(".list_c2 input").click(function() {
				if(this.checked) {
					$(this).closest("li.list1").find(".list_c1 input")[0].checked = true;
				}else {
					var list_c2 = $(this).closest("li.list1").find(".list_c2 input:checked");
					if(list_c2.length == 0) {
						$(this).closest("li.list1").find(".list_c1 input")[0].checked = false;
					}
				}
				$("#studentCount").html($("#studentList").find(".list_c2 input:checked").length);
			});
			//老师组织架构全选
	      	$("#studentAll").click(function() {
	      		if(this.checked) {
	      			var list = $("#studentList").find("input");
	      			list.each(function(i, v){
						v.checked = true;
					});
	      		}else {
	      			var list = $("#studentList").find("input:checked");
	      			list.each(function(i, v){
						v.checked = false;
					});
	      		}
	      		$("#studentCount").html($("#studentList").find(".list_c2 input:checked").length);
	      	})
	      	$("#studentSure").click(function() {
	      		$('.ueureiu').hide();
				$("#xs_div_box").hide();
				var length = $("#studentList").find(".list_c2 input:checked").length;
				if(length > 0){
					$(".weui_cell_ft").html("已选择" + length + "个班级");
				}else {
					$(".weui_cell_ft").html("请选择");
				}
	      	})
      	});
		//老师组织架构弹出
      	$("#ls_div").click(function() {
      		sendModel = 2;
      		$('.ueureiu').show();
      		$("#ls_xs_check").hide();
      		$("#ls_div_box").show();
      		//上下级拉动
      		$("#teacherList .js-category").each(function(i, v) {
	    		v.removeEventListener("click", categoryClick, false);
	    		v.addEventListener('click', categoryClick);
	    	})
      		$('.list_c1 input').click(function() {
      			if(this.checked) {
      				var list = $(this.closest("li.list1")).find("input");
      				list.each(function(i, v){
						v.checked = true;
					});
      			}else {
      				var list_c2 = $(this.closest("li.list1")).find(".list_c2 input:checked");
      				list_c2.each(function(i, v){
						v.checked = false;
					});
      				var list_c3 = $(this.closest("li.list1")).find(".list_c3 input:checked");
      				list_c3.each(function(i, v){
						v.checked = false;
					});
      			}
      			$("#teacherCount").html($("#teacherList").find(".list_c3 input:checked").length);
			});
			$(".list_c2 input").click(function() {
				var list_c1 = this.id.substr(0,this.id.indexOf("_"));
				if(this.checked) {
					var list = $(this).closest(".weui_cells").find(".list_c3 input");
					list.each(function(i, v){
						v.checked = true;
					});
					$("#" + list_c1)[0].checked = true;
				}else {
					var list_c2 = $(this).closest(".weui_cells").find(".list_c3 input:checked");
					list_c2.each(function(i, v){
						v.checked = false;
					});
					var list_c2_length = $(this).closest(".page-category").find("input:checked").length;
					if(list_c2_length == 0) {
						$("#" + list_c1)[0].checked = false;
					}
				}
				$("#teacherCount").html($("#teacherList").find(".list_c3 input:checked").length);
			});
			$(".list_c3 input").change(function() {
				var list_c3_length = $(this).closest('ul').find("input:checked").length;
				var list_c2 = this.id.substr(0,this.id.lastIndexOf('_'));
				var list_c1 = this.id.substr(0,this.id.indexOf('_'));
				if(list_c3_length == 0) {
					$("#" + list_c2)[0].checked = false;
					var list_c2_length = $(this).closest(".page-category").find("input:checked").length;
					if(list_c2_length == 0) {
						$("#" + list_c1)[0].checked = false;
					}
				}else {
					$("#" + list_c2)[0].checked = true;
					$("#" + list_c1)[0].checked = true;
				}
				$("#teacherCount").html($("#teacherList").find(".list_c3 input:checked").length);
			});
      	})
      	$("#teacherSure").click(function() {
      		$('.ueureiu').hide();
			$("#ls_div_box").hide();
			var length = $("#teacherList").find(".list_c3 input:checked").length;
			if(length > 0){
				$(".weui_cell_ft").html("已选择" + length + "位老师");
			}else {
				$(".weui_cell_ft").html("请选择");
			}
      	})
	});
	function categoryClick() {
		$parent = $(this).closest('li');
		if($parent.hasClass('js-show')){
            $parent.removeClass('js-show');
            $parent.find('i').removeClass('icon-35').addClass('icon-74');
        }else{
            $parent.siblings().removeClass('js-show');
            $parent.addClass('js-show');
            $parent.siblings().find('i').removeClass('icon-35').addClass('icon-74');
            $parent.find('i').removeClass('icon-74').addClass('icon-35');
        }
	}
	function loadStudent() {
		$.ajax({
	 		url : basePath + "/studentOrganize",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			if(data != null && data.length > 0) {
	 				studentData.list = data;
	 				loadStudentHtml(studentData);
	 			}
	 		}, error:function(){
	 			alert("查询异常");
      			}
	 	});
	}
	function loadStudentHtml(studentData) {
		var myTemplate = Handlebars.compile($("#student-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
    		if(v1 == v2) {
    			//满足添加继续执行
    			return options.fn(this);
    		}else {
    			//不满足条件执行{{else}}部分
    			return options.inverse(this);
    		}
    	});
		Handlebars.registerHelper("compare", function(v1,v2,options) {
			if(v1 > v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		$('#studentList').html(myTemplate(studentData));
	}
	function loadTeacher() {
		$.ajax({
	 		url : basePath + "/teacherOrganizeGroup",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			if(data != null && data.length > 0) {
	 				teacherData.list = data;
	 				loadTeacherHtml(teacherData);
	 			}
	 		}, error:function(){
	 			alert("查询异常");
      			}
	 	});
	}
	function loadTeacherHtml(teacherData) {
		var myTemplate = Handlebars.compile($("#teacher-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
    		if(v1 == v2) {
    			//满足添加继续执行
    			return options.fn(this);
    		}else {
    			//不满足条件执行{{else}}部分
    			return options.inverse(this);
    		}
    	});
		Handlebars.registerHelper("compare", function(v1,v2,options) {
			if(v1 > v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		$('#teacherList').html(myTemplate(teacherData));
	}
	function selectmenu(n){
		var eleMore = document.getElementById("menu_"+n);
		if(eleMore.style.display=="none"){
			eleMore.style.display = 'block';
			$("#cell_"+n).removeClass("icon-74");
			$("#cell_"+n).addClass("icon-35 ");
		}else{
			eleMore.style.display = 'none';
			$("#cell_"+n).removeClass("icon-35");
			$("#cell_"+n).addClass("icon-74");
		}
	}
	function noticeSubmit() {
		var content = $("#content").val();
		if(content.trim().length==0){
			alert("请输入通知内容");
			return;
		}
		if($(".weui_cell_ft").html() == "请选择") {
			alert("请选择发送对象");
			return;
		}
		var ids = new Array();
		if(sendModel == 1) {
			var list = $("#studentList").find(".list_c2 input:checked");
			list.each(function(i, v) {
				ids.push($(v).val());
			})
		}else {
			var list = $("#teacherList").find(".list_c3 input:checked");
			list.each(function(i, v) {
				ids.push(parseInt($(v).val()));
			})
		}
		if($("#notice-submit").hasClass('active')) return;
		$("#notice-submit").addClass('active');
		$.ajax({
	 		url : basePath + "/ls/notice/create",
	 		type : "post",
	 		data : {
	 			sendModel: sendModel,
	 			ids: ids.toString(),
	 			content: content,
	 			noticeType: parseInt("${noticeType}")
	 		},
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			$("#notice-submit").removeClass('active');
	 			if(data.code == '000') {
	 				$.toast("通知创建成功");
	 				$("#content").val(null);
	 				$("#img1").html("");
	 				$("#studentBack").trigger("click");
	 				$("#teacherBack").trigger("click");
	 				loadTodayNotice();
	 			}else{
	 				$.toast(data.msg, "cancel");
	 			}
	 		}, error:function(){
	 			alert("提交异常");
      			}
	 	});
	}
	
	//拍照或从手机相册中选图接口
    $('#filePicker').on('click', function () {
        wx.chooseImage({
            count: 6,
            needResult: 1,
            sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
           		var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
           		wxuploadImage(localIds);
            },
            fail: function (res) {
                alterShowMessage("操作提示", JSON.stringify(res), "1", "确定", "", "", "");
            }

        });
    });
	function wxuploadImage(localIds) {  
		var localId = localIds.pop();
        wx.uploadImage({  
            localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得  
            isShowProgressTips: 1, // 默认为1，显示进度提示  
            success: function (res) {  
                mediaId = res.serverId; // 返回图片的服务器端ID  
                wechatMediaDownload(mediaId);
                if(localIds.length > 0){
                	wxuploadImage(localIds);
                }
            },  
            fail: function (error) {  
                alert(Json.stringify(error));  
            }  
        });
   }  
	function wechatMediaDownload(mediaId) {
	   	var params = {};
	   	params.mediaId = mediaId;
        params.attachmentType = "image";
        params.noticeType = parseInt("${noticeType}");
        params.relationType = "${relationType}";
        $.ajax({
	 		url : basePath + "/ls/attchment/upload/wx",
	 		type : "post",
	 		data : params,
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			if(data.code != '000') {
	 				$.toast(data.msg, "cancel");
	 			}else {
	 				$('#img1').append('<li class="weui_uploader_file" data-id="'+data.data.id+'" style="margin-right:0;margin-bottom:16px;position: relative;"><div class="img-del" onclick="imgDel(this)"><span class="icon icon-26"></span></div><img onclick="imgClick(this)" src="'+ imgUrl + data.data.attachmentUrl +'"/></li>'); 
	 			}
	 		}, error:function(){
	 			alert("上传异常");
      			}
	 	});
   }
	
	function initHandingAttach() {
		$.ajax({
	 		url : basePath + "/ls/attchment/handing",
	 		type : "post",
	 		dataType : "json",
	 		data: {
	 			relationType: "${relationType}"
	 		},
	 		async : false,
	 		success : function(data) {
	 			if(data != null && data.length > 0) {
	 				for(var itm in data) {
	 					if(data[itm].attachmentType == 'image') {
	 						$('#img1').append('<li class="weui_uploader_file" data-id="'+data[itm].id+'" style="margin-right:0;margin-bottom:16px;position: relative;"><div class="img-del" onclick="imgDel(this)"><span class="icon icon-26"></span></div><img onclick="imgClick(this)" src="'+ imgUrl + data[itm].attachmentUrl +'"/></li>');          
	 					}else {
	 						$("#fileDiv").show();
	 						$("#fileList").append('<li>'
                            + '<span class="file_name" title="' + data[itm].attachmentName + '">' + data[itm].attachmentName + '</span>'
                            + '<div class="set" data-id="'+data[itm].id+'">'
                                + '<span class="delete" onclick="fileDel(this)">删</span>'
                                + '<a href="'+imgUrl + data[itm].attachmentUrl+'"><span class="preview">预览</span></a>'
                            + '</div>'    
                        + '</li>');
	 					}
	 				}
	 			}
	 		}, error:function(){
	 			alert("查询异常");
   			}
	 	});
	}
   
   function loadTodayNotice() {
	   $.ajax({
         	url : basePath + "/ls/notices/sender/today",
 	 		type : "post",
 	 		dataType : "json",
 	 		data : {
 	 			noticeType: "${noticeType}"
 	 		},
            success: function(data){
            	var result = {};
            	result.rows = data;
           	  	loadNoticeHtml(result);
           	  	paragraph();
             },
             error: function(xhr, type){
                 
             }
         });
   }
   function loadNoticeHtml(data){
 		if(data.rows.length > 0) {
 			var myTemplate = Handlebars.compile($("#notice-table-template").html());
 			Handlebars.registerHelper("equal", function(v1,v2,options) {
 				if(v1 == v2) {
 					//满足添加继续执行
 					return options.fn(this);
 				}else {
 					//不满足条件执行{{else}}部分
 					return options.inverse(this);
 				}
 			});
 			Handlebars.registerHelper("compare", function(v1,v2,options) {
 				if(v1 > v2) {
 					//满足添加继续执行
 					return options.fn(this);
 				}else {
 					//不满足条件执行{{else}}部分
 					return options.inverse(this);
 				}
 			});
 			Handlebars.registerHelper("dateFormat", function(v1) {
 				return getTime(v1, "yyyy-MM-dd hh:mm:ss");
 			});
 			$('#noticeList').html(myTemplate(data));
 		}
	}
	function paragraph() {
		$("#noticeList .moments__post").each(function(i, v) {
			//定义文本
			const paragraph = $($(this).find('.paragraph'));
			const paragraphText = paragraph.text();
			const paragraphLength = paragraph.text().length;
			//定义文章长度
			const maxParagraphLength = 80;
			//定义全文按钮
			const paragraphExtender = $($(this).find('.paragraphExtender'));
			var toggleFullParagraph = false;
			
			//定义全文按钮
			if (paragraphLength < maxParagraphLength) {
			  paragraphExtender.hide();
			} else {
			  paragraph.html(paragraphText.substring(0, maxParagraphLength) + '...');
			  paragraphExtender.click(function(){
			    if (toggleFullParagraph) {
			      toggleFullParagraph = false;
			      paragraphExtender.html('全文');
			      paragraph.html(paragraphText.substring(0, maxParagraphLength) + '...');
			    } else {
			      toggleFullParagraph = true;
			      paragraphExtender.html('收起');
			      paragraph.html(paragraphText);
			    }
			  });
			};
		});
   }
	 
	!function() {
        var fu = {
            FileArea: $('#uploadTheFile'),
            FileInfoBox: $('.upload_info'),
            FileName: $('.upload_info .file_name'),
            FileDel: $('.upload_info .delete'),
            FilePreview: $('.upload_info .preview'),
            FormArea: $('#uploadForm'),
            Loading: $('.upload_info>img'),
            Cover: $('.upload_info>.cover'),
            ShowTheUploadWin: function() {
                return fu.FileArea.click();
            },
            FileChange: function() {
                fu.FileArea.on('change', function() {
                    fu.FileUpload($(this)[0]);
                });
            },
            FileUpload: function(file) {
           	 uploadFile(file,fu);
            },
            UploadComplete: function(){
                fu.Loading.hide();
                fu.Cover.hide();
            },
            Unit: function(value) {
                value = (value >= 1024 && value < 1024 * 1024) 
                        ? (value / 1024).toFixed(2) + 'KB' 
                        : (value / (1024 * 1024)).toFixed(2) + 'MB'; 
                return value;
            },
            init: function() {
                fu.FileArea.next('a').on('click', function() {
                    fu.ShowTheUploadWin();
                });
                fu.FileChange();
            }
        };
        fu.init();
    }();
	function uploadFile(file, fu) {
	    if (file.files && file.files[0]) {
	    	var fileObj = file.files[0];
	    	if(fileObj.size >= 52428800) {
	    		$.alert("文件太大，文件大小超过了50M");
	    		return;
	    	}
	    	fu.Loading.show();
	    	fu.Cover.show();
	    	var xhr = new XMLHttpRequest();
           xhr.open('POST', basePath + "/ls/attchment/upload/file");
           xhr.onload = function () {
           	fu.UploadComplete();
               if (xhr.status === 200) {
               	var resp = JSON.parse(xhr.response);
               	if(resp.code == '000') {
               		$.toast("上传成功");
               		$("#fileDiv").show();
               		fu.FileInfoBox.find('ul').append('<li>'
                               + '<span class="file_name" title="' + resp.data.attachmentName + '">' + resp.data.attachmentName + '</span>'
                               + '<div class="set" data-id="'+resp.data.id+'">'
                                   + '<span class="delete" onclick="fileDel(this)">删</span>'
                                   + '<a href="'+imgUrl + resp.data.attachmentUrl+'"><span class="preview">预览</span></a>'
                               + '</div>'    
                           + '</li>');
               	}else {
               		$.toptips(resp.msg);
               	}
               }
           };
           xhr.onerror = function () {
           	alert("上传异常");
           };
           var fd = new FormData();
           // 添加参数
           var fileName = fileObj.name;
           fd.append('attachmentName', fileName);
           fd.append('attachmentSize', fileObj.size);
           fd.append('files', fileObj);
           fd.append('attachmentType', fileName.substr(fileName.lastIndexOf(".")+1, fileName.length));
           fd.append('relationType', "${relationType}");
           // 触发上传
           xhr.send(fd);
	    }
	}
</script>
</body>
</html>